<?php
include "../conn.php";

echo $StudentId = $_POST["StduentId"];

$ProjectId = $_POST['ProjectId'];

echo $method = $_POST['method'];

$intention = $_POST['intention'];

$Id = $_POST['Id'];


/*
 * 选课
 */
$checksql = "select * from choosesubject WHERE StudentId=$StudentId";
$checkresult = mysqli_query($conn, $checksql);
$checkpidsql="select * from project WHERE Student_StudentId=$StudentId";
$checkpidresult=mysqli_query($conn,$checkpidsql);
echo mysqli_num_rows($checkpidresult);
if ($method == "choose") {
    if (mysqli_num_rows($checkpidresult)==0&&mysqli_num_rows($checkresult) == 0) {
        $checkksql = "select * from probyself WHERE StudentId=$StudentId";
        $checkkreult = mysqli_query($conn, $checkksql);

        if ($checkkreult->num_rows == 0) {
            $sql = "insert into choosesubject VALUES ($StudentId,$ProjectId,'$intention','0')";
            if ($result = mysqli_query($conn, $sql)) {
                echo("选课成功!");
            }
        } else {
            echo("你已经自拟题目");
        }
    }
    else {
        echo("你已经选课!");
    }
}

/*
 * 删除选题
 */
if ($method == "deletepro") {
    $sql = "delete from choosesubject where StudentId=$Id";
    if ($conn->query($sql)) {
        echo("删除成功");
    }
} /*
     * 删除自拟
     */
else if ($method == "deletedself") {
    $sql = "delete from probyself where ProjectId=$Id";
    if ($conn->query($sql)) {
        echo("删除成功");
    }
} /*
 * 重新选课
 */
elseif ($method == "reset") {
    $sql = "delete from choosesubject where StudentId=$Id";
    if ($conn->query($sql)) {
        echo("删除成功");
    }
}


?>